package com.lsh.mq;

import com.lsh.domain.UserPraise;
import com.lsh.util.PraiseRedisUtil;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.apache.log4j.Logger;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.context.request.async.DeferredResult;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import java.util.concurrent.Future;

/**
 * 点赞消费者
 * @author Administrator
 * @date 2019/10/02 23:18
 */
public class PraiseConsumer implements MessageListener {

    @Resource
    RedisTemplate redisTemplate;

    private Logger log = Logger.getLogger(this.getClass());

    // 异步接受方法，当有队列中有新的消息产生时，该方法被自动调用
    @Override
    public void onMessage(Message message) {

        try {
            UserPraise userPraise = (UserPraise) ((ActiveMQObjectMessage)message).getObject();

            log.info("消费者>>>>>>>>>>>用户Id:" + userPraise.getUserId() + " 给评价ID: " + userPraise.getCommentId() + "点赞/取消点赞");
        } catch (JMSException e) {
            e.printStackTrace();
        }

    }
}
